#ifndef CLOUDAPPENGINE_CAECONNECTIONPOOL_H
#define CLOUDAPPENGINE_CAECONNECTIONPOOL_H

#include <shared_mutex>
#include "CaeSocketAgent.h"

class CaeConnectionPool {
public:
    CaeConnectionPool();
    virtual ~CaeConnectionPool();

    void Add(std::string connectionId, std::shared_ptr<CaeSocketAgent> socketAgent);
    void Remove(const std::shared_ptr<CaeSocketAgent>& socketAgent);
    void Remove(std::string &connectionId);
    void Clear();

    size_t Size();

    std::vector<std::shared_ptr<CaeSocketAgent>> GetAll();
    std::vector<std::shared_ptr<CaeSocketAgent>> GetAllValid();

    std::shared_ptr<CaeSocketAgent> GetIfExist(const std::string& connectionId);
    std::shared_ptr<CaeSocketAgent> Pop(const std::string& connectionId);
private:
    std::map<std::string, std::shared_ptr<CaeSocketAgent>> m_socketAgentMap;
    std::shared_mutex m_mapMutex;
};


#endif //CLOUDAPPENGINE_CAECONNECTIONPOOL_H
